package com.miguo.utils;

import android.app.AlarmManager;
import android.content.Intent;

import com.miguo.app.AppContext;

import java.text.SimpleDateFormat;
import java.util.Calendar;

/**
 * File Names: SignAlarmUtils
 * Describe:
 * User: LinXiaoZhi(87100854@qq.com)
 * Date: 2015-08-16
 * Time: 22:10
 */
public class SignAlarmUtils {

    public static final int HOUR_OF_DAY = 24;
    public static final int SIGN_TIME = 20;

    public static void signAlarm() {
        AlarmSign sign = new AlarmSign(AppContext.getContext());
        sign.updateAlarmTimeForAction("com.miguo.ui.sign_alarm", getStartTime(), AlarmManager.INTERVAL_DAY);
    }

    public static long getStartTime() {
        Calendar calendar = Calendar.getInstance();

        int hour = SIGN_TIME;
        if (calendar.get(Calendar.HOUR_OF_DAY) >= 21) {
            hour = HOUR_OF_DAY;
        }

        calendar.set(Calendar.HOUR_OF_DAY, hour);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);

//        Calendar calendar = Calendar.getInstance(Locale.getDefault());
//        calendar.setTimeInMillis(System.currentTimeMillis());
//        calendar.set(Calendar.HOUR_OF_DAY, 0);
//        calendar.set(Calendar.MINUTE, 0);
//        calendar.set(Calendar.SECOND, 0);
//        calendar.set(Calendar.MILLISECOND, 0);

        return calendar.getTimeInMillis();
    }

    public static void unSignAlarm() {
        Intent intent = new Intent("com.miguo.ui.sign_alarm");
        new AlarmSign(AppContext.getContext()).cancelAlarmTime(intent);
    }

    private static int getMinute() {
        return (int) (Math.random() * 60.0);
    }

    private static void outputTime(Calendar calendar) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = format.format(calendar.getTime());
    }
}